package top.jojoace.JPA.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import top.jojoace.JPA.model_DDL.BothWay_OneToMany.BW_StudentItem;
import top.jojoace.JPA.model_DDL.OneWay_OneToMany.OW_StudentItem;
import top.jojoace.JPA.repository.BWStudentRepository;
import top.jojoace.JPA.repository.OWStudentRepository;

@Service
public class StudentServiceImpl implements StudentService{

    @Autowired
    private BWStudentRepository BWStudentRepository;

    @Autowired
    private OWStudentRepository OWStudentRepository;

    @Override
    public BW_StudentItem selectBWStudentById(int id) {
        return this.BWStudentRepository.findOneById(id);
    }

    @Override
    public OW_StudentItem selectOWStudentById(int id) {
        return this.OWStudentRepository.findOW_StudentById(id);
    }


    /**
     *
     * 分页
     *
     *
     *
     * @param pageNum
     * @param size
     * @return
     */
    @Override
    public Page<BW_StudentItem> getLatestPagingStudnets(Integer pageNum, Integer size) {
        /**
         *
         * 分页
         *
         * Pageable page = PageRequest.of(pageNum, size, Sort.by("id").descending());
         *
         * pageNum 启始
         * size 长度
         * Sort.by("id").descending() 排序
         *
         */
        Pageable page = PageRequest.of(pageNum, size, Sort.by("id").descending());
        return this.BWStudentRepository.findAll(page);
    }
}
